package com.wyp168.leetcode.treenode;

/**
 * @ClassName GetMaxDepth
 * @Description TODO
 * @Author wyp168
 * @Date 2022/6/23 13:16
 */
public class GetMaxDepth {
    public static void main(String[] args) {

        TreeNode parentNode = new TreeNode();
        parentNode.val = 1;

        TreeNode node1 = new TreeNode();
        node1.val = 2;

        TreeNode node2 = new TreeNode();
        node2.val = 3;

        TreeNode node3 = new TreeNode();
        node3.val = 4;
        parentNode.left = node1;
        parentNode.right = node2;
        node1.left = node3;

        System.out.println(maxDepth(parentNode));


    }

    public static int maxDepth(TreeNode root) {
        return root == null ? 0 : Math.max(maxDepth(root.left),maxDepth(root.right)) + 1;
    }
}
